<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head>
      <#include "/common/elibs.html">
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
  </head>
  <script>var index;
  </script><body>
    <div class="x-body">
        <form class="layui-form">
            <input type="hidden" name="idxProAdmin" id="idxProAdmin" value="${id}"/>
            <input type="hidden" name="idFixedValueInsuredLineAss" id="idFixedValueInsuredLineAss" value="${subsetId}"/>
            <input type="hidden" name="paramsType" id="paramsType" value="${type}"/>

            <div class="layui-form-item">
                <label class="layui-form-label">
                    开始时间
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="beginTime" name="beginTime"
                           autocomplete="off" class="layui-input" disabled style="background-color: #b7b1b1;">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">
                    结束时间
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="endTime" name="endTime"
                           autocomplete="off" class="layui-input" disabled style="background-color: #b7b1b1;">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">
                    距离结束时间天数
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="differenceTime" name="differenceTime"
                           autocomplete="off" class="layui-input" disabled style="background-color: #b7b1b1;">
                </div>
            </div>

            <div class="layui-form-item" id="powerSupply" style="padding: 20px; background-color: #F2F2F2;">


            </div>




            <div class="layui-form-item">
                <label for="" class="layui-form-label">
                </label>
                <button  class="layui-btn" lay-filter="add" type=button codeTyle="3" lay-submit="">
                    提交
                </button>
            </div>
      </form>
    </div>
    <script>

        function powerSupply(){
            var html = '<div class=\'layui-col-md6 powerSupply\' style=\'width: 100%;\'>\n' +
                '                    <div class=\'layui-card\'>\n' +
                '                        <div class="layui-card-header">各级分头变比额定电流（注填不下另附表）</div>\n' +
                '                        <div class="layui-form-item">\n' +
                '                            <label for="separately" class="layui-form-label">\n' +
                '                                <span class="x-red">*</span>分头\n' +
                '                            </label>\n' +
                '                            <div class="layui-input-inline">\n' +
                '                                <input type="text" id="separately" name="separately" lay-verify="required" placeholder="请输入"\n' +
                '                                       autocomplete="off" class="layui-input" >\n' +
                '                            </div>\n' +
                '                            <div class="layui-form-mid layui-word-aux">\n' +
                '                                <span class="x-red">*</span>\n' +
                '                            </div>\n' +
                '                        </div>\n' +
                '\n' +
                '                        <div class="layui-form-item">\n' +
                '                            <label for="highVoltage" class="layui-form-label">\n' +
                '                                <span class="x-red">*</span>高压（V）\n' +
                '                            </label>\n' +
                '                            <div class="layui-input-inline">\n' +
                '                                <input type="text" id="highVoltage" name="highVoltage" lay-verify="required" placeholder="请输入"\n' +
                '                                       autocomplete="off" class="layui-input" >\n' +
                '                            </div>\n' +
                '                            <div class="layui-form-mid layui-word-aux">\n' +
                '                                <span class="x-red">*</span>\n' +
                '                            </div>\n' +
                '                        </div>\n' +
                '\n' +
                '                        <div class="layui-form-item">\n' +
                '                            <label for="highVoltageCurrent" class="layui-form-label">\n' +
                '                                <span class="x-red">*</span>高压电流（A）\n' +
                '                            </label>\n' +
                '                            <div class="layui-input-inline">\n' +
                '                                <input type="text" id="highVoltageCurrent" name="highVoltageCurrent" lay-verify="required" placeholder="请输入"\n' +
                '                                       autocomplete="off" class="layui-input" >\n' +
                '                            </div>\n' +
                '                            <div class="layui-form-mid layui-word-aux">\n' +
                '                                <span class="x-red">*</span>\n' +
                '                            </div>\n' +
                '                        </div>\n' +
                '                        <div class="layui-form-item">\n' +
                '                            <label for="voltage" class="layui-form-label">\n' +
                '                                <span class="x-red">*</span>电压（V）\n' +
                '                            </label>\n' +
                '                            <div class="layui-input-inline">\n' +
                '                                <input type="text" id="voltage" name="voltage" lay-verify="required" placeholder="请输入"\n' +
                '                                       autocomplete="off" class="layui-input" >\n' +
                '                            </div>\n' +
                '                            <div class="layui-form-mid layui-word-aux">\n' +
                '                                <span class="x-red">*</span>\n' +
                '                            </div>\n' +
                '                        </div>\n' +
                '                        <div class="layui-form-item">\n' +
                '                            <label for="voltageCurrent" class="layui-form-label">\n' +
                '                                <span class="x-red">*</span>电压电流（A）\n' +
                '                            </label>\n' +
                '                            <div class="layui-input-inline">\n' +
                '                                <input type="text" id="voltageCurrent" name="voltageCurrent" lay-verify="required" placeholder="请输入"\n' +
                '                                       autocomplete="off" class="layui-input" >\n' +
                '                            </div>\n' +
                '                            <div class="layui-form-mid layui-word-aux">\n' +
                '                                <span class="x-red">*</span>\n' +
                '                            </div>\n' +
                '                        </div>\n' +
                '                        <div class="layui-form-item">\n' +
                '                            <label for="lowVoltage" class="layui-form-label">\n' +
                '                                <span class="x-red">*</span>低压（V）\n' +
                '                            </label>\n' +
                '                            <div class="layui-input-inline">\n' +
                '                                <input type="text" id="lowVoltage" name="lowVoltage" lay-verify="required" placeholder="请输入"\n' +
                '                                       autocomplete="off" class="layui-input" >\n' +
                '                            </div>\n' +
                '                            <div class="layui-form-mid layui-word-aux">\n' +
                '                                <span class="x-red">*</span>\n' +
                '                            </div>\n' +
                '                        </div>\n' +
                '                        <div class="layui-form-item">\n' +
                '                            <label for="lowVoltageCurrent" class="layui-form-label">\n' +
                '                                <span class="x-red">*</span>低压电流（A）\n' +
                '                            </label>\n' +
                '                            <div class="layui-input-inline">\n' +
                '                                <input type="text" id="lowVoltageCurrent" name="lowVoltageCurrent" lay-verify="required" placeholder="请输入"\n' +
                '                                       autocomplete="off" class="layui-input" >\n' +
                '                            </div>\n' +
                '                            <div class="layui-form-mid layui-word-aux">\n' +
                '                                <span class="x-red">*</span>\n' +
                '                            </div>\n' +
                '                        </div>\n' +
                '\n' +
                '                        <div class=\'layui-form-item\'>\n' +
                '                            <div class=\'layui-btn\' type=button onclick=\'powerSupply()\'>添加电源信息</div>\n' +
                '                            <div class=\'layui-btn\' type=button onclick=\'deleteTemp(this)\'>删除当前电源信息</div>\n' +
                '                        </div>\n' +
                '                    </div>\n' +
                '                </div>';
            $("#powerSupply").append(html);
            renderForm();
        }


        function deleteTemp(o){
            $(o).parent().parent().parent().remove();
        }

        $(function(){
            getProTime($("#idxProAdmin").val(),30);
            var type = $("#paramsType").val();
            if(type === 'edit'){
                ajaxFun('get','/pc/project/getProtectionFixedValueReportingInfo',{"idProAdmin":$("#idxProAdmin").val()},function(data){
                    if(data.code != 0){
                        alertFun(data);
                    }else{
                        var fixedValueInsuredTransformerNameplateAssList = data.data.fixedValueInsuredTransformerNameplateAssList;
                        var j=0;
                        for(var i=0;i<fixedValueInsuredTransformerNameplateAssList.length;i++){
                            powerSupply();
                        }
                        $(".layui-card").each(function(){
                            $(this).children(".layui-form-item").children(".layui-input-inline")
                                .children("input[name=separately]").val(fixedValueInsuredTransformerNameplateAssList[j].separately);
                            $(this).children(".layui-form-item").children(".layui-input-inline")
                                .children("input[name=highVoltage]").val(fixedValueInsuredTransformerNameplateAssList[j].highVoltage);
                            $(this).children(".layui-form-item").children(".layui-input-inline")
                                .children("input[name=highVoltageCurrent]").val(fixedValueInsuredTransformerNameplateAssList[j].highVoltageCurrent);
                            $(this).children(".layui-form-item").children(".layui-input-inline")
                                .children("input[name=voltage]").val(fixedValueInsuredTransformerNameplateAssList[j].voltage);
                            $(this).children(".layui-form-item").children(".layui-input-inline")
                                .children("input[name=voltageCurrent]").val(fixedValueInsuredTransformerNameplateAssList[j].voltageCurrent);

                            $(this).children(".layui-form-item").children(".layui-input-inline")
                                .children("input[name=lowVoltage]").val(fixedValueInsuredTransformerNameplateAssList[j].lowVoltage);
                            $(this).children(".layui-form-item").children(".layui-input-inline")
                                .children("input[name=lowVoltageCurrent]").val(fixedValueInsuredTransformerNameplateAssList[j].lowVoltageCurrent);
                            j++
                        })
                    }
                })
            }else if(type === 'add'){
                powerSupply();
            }
        })

        layui.use(['form','layer'], function() {
            $ = layui.jquery;
            var form = layui.form
                , layer = layui.layer, layedit = layui.layedit;

            //自定义验证规则
            form.verify({
                otherReq: function(value,item){
                    var $ = layui.$;
                    var verifyName=$(item).attr('name')
                        , verifyType=$(item).attr('type')
                        ,formElem=$(item).parents('.layui-form')//获取当前所在的form元素，如果存在的话
                        ,verifyElem=formElem.find('input[name='+verifyName+']')//获取需要校验的元素
                        ,isTrue= verifyElem.is(':checked')//是否命中校验
                        ,focusElem = verifyElem.next().find('i.layui-icon');//焦点元素
                    if(!isTrue || !value) {
                        //定位焦点
                        focusElem.css(verifyType == 'radio' ? {"color": "#FF5722"} : {"border-color": "#FF5722"});
                        //对非输入框设置焦点
                        focusElem.first().attr("tabIndex", "1").css("outline", "0").blur(function () {
                            focusElem.css(verifyType == 'radio' ? {"color": ""} : {"border-color": ""});
                        }).focus();
                        return '必填项不能为空';
                    }
                }
            });




            //添加电源信息
            layui.$('#addPowerSupply').on('click', function(){
                powerSupply();
            });

            //添加电源信息
            layui.$('#addPowerSupply').on('click', function(){
                powerSupply();
            });


            //监听提交
            form.on('submit(add)', function (t) {
                addSubmit(3);
            });



        });

        function addSubmit(submitState){
            var myArray=new Array(),i = 0;
            $(".layui-card").each(function(){
                var data = {
                    "separately":$(this).children(".layui-form-item").children(".layui-input-inline")
                        .children("input[name=separately]").val(),
                    "highVoltage" : $(this).children(".layui-form-item").children(".layui-input-inline")
                        .children("input[name=highVoltage]").val(),
                    "highVoltageCurrent" : $(this).children(".layui-form-item").children(".layui-input-inline")
                        .children("input[name=highVoltageCurrent]").val(),
                    "voltage" : $(this).children(".layui-form-item").children(".layui-input-inline")
                        .children("input[name=voltage]").val(),
                    "voltageCurrent" : $(this).children(".layui-form-item").children(".layui-input-inline")
                        .children("input[name=voltageCurrent]").val(),

                    "lowVoltage" : $(this).children(".layui-form-item").children(".layui-input-inline")
                        .children("input[name=lowVoltage]").val(),
                    "lowVoltageCurrent" : $(this).children(".layui-form-item").children(".layui-input-inline")
                        .children("input[name=lowVoltageCurrent]").val()
                }
                myArray[i] = data;
                i++
            })


            var params = {
                //tcaDescribe : layui.layedit.getContent(index),
                "idProAdmin": $("#idxProAdmin").val(),
                "idFixedValueInsured": $("#idFixedValueInsuredLineAss").val(),
                "fixedValueInsuredTransformerNameplateAssList":myArray
            }
            if (true) {
                ajaxFunJson('post','/pc/project/updateProtectionFixedValueReporting',JSON.stringify(params),function(data){
                    if (data.code != 0) {
                        alertFun(data);
                    } else {
                        window.location.href = path + "/modules/project/towPro/bhdzbs/list.html";
                        console.log("success !");
                    }
                })
                return false;
            }
        }
    </script></body></html>